<template>
  <view class="content">
    <top-bar :isIndex="true"></top-bar>
    <!-- 首页 -->
    <index-swiper :bannerList="bannerList"></index-swiper>
    <!-- 底部 -->
    <footer-bar></footer-bar>
  </view>
</template>

<script>
import topBar from "@/components/topBar.vue";
import indexSwiper from "@/components/swiper.vue";
import footerBar from "@/components/footerBar.vue";
import { GET_BANNER_LIST, STORE_GET_INFO } from "@/api";
import goodsMixin from "@/mixins/goods.js";
export default {
  name: "IndexPage",
  components: {
    topBar,
    footerBar,
    indexSwiper
  },
  mixins: [goodsMixin],
  data() {
    return {
      storeId: this.$store.state.storeConf.store_id,
      tableId: this.$store.state.storeConf.table_id,
      deviceNum: this.$store.state.storeConf.device_num,
      bannerList: []
    };
  },
  onShow() {
    // 获取设备绑定的门店及餐桌  全局只请求一次
    let t = this
    let that = this
    setTimeout(() => {
      let storeConf = this.$storage.get("storeConf", false);
      if (storeConf.table_id) {
        storeConf = JSON.parse(storeConf);
        this.getBannerList(storeConf.store_id);
        this.getIntegralCartList(storeConf.table_id, storeConf.store_id);
        this.getCartList(storeConf.table_id, storeConf.store_id);
      } else {
        // let deviceNum = '14aa3bed-1dc1-413f-c69e-0a9520ebe7fc';
        // 获取设备uuid
        // #ifdef APP-PLUS
        this.deviceNum = plus.device.uuid;
        // #endif
        that.getStoreInfo(this.deviceNum);
      }
    }, 200)
  },
  methods: {
    // 获取门店信息
    getStoreInfo(deviceNum) {
      let that = this;
			if (!deviceNum) {
				that.$common.navigateTo("/pages/store/login");
				return
			}
      deviceNum = deviceNum
        ? deviceNum
        : "F374F8D4-962E-4CFC-BB18-AA13CEE954B6";
      that.$_get(STORE_GET_INFO, { device_num: deviceNum }).then(res => {
        if (res.code === 1) {
          let storeConf = res.data
          that.$set(storeConf, 'device_num', deviceNum)
          that.$store.commit("storeConf", storeConf);
          that.getBannerList(res.data.store_id, res.data.table_id, deviceNum);
					
          that.getIntegralCartList(res.data.table_id, res.data.store_id, deviceNum);
          that.getCartList(res.data.table_id, res.data.store_id, deviceNum);
        } else {
          that.$common.navigateTo("/pages/store/login");
        }
      });
    },
    // 获取首页轮播图
    getBannerList(storeId, tableId, deviceNum) {
      let that = this;
      let qsData = {
        store_id: storeId
      }
      if (tableId) {
        qsData.table_id = tableId
      }
      if (deviceNum) {
        qsData.device_num = deviceNum
      }
      that.$_get(GET_BANNER_LIST, qsData).then(res => {
        if (res.code === 1) {
          this.bannerList = res.data;
        } else {
          console.log(res.msg);
        }
      });
    }
  }
};
</script>

<style scoped>
.content {
  background: #333333;
  font-size: 14px;
}
.main_left_cont {
  background: #2a2a2a;
  height: 100%;
}
.main_title {
  padding: 0 105px 0 105px;
  margin-bottom: 14px;
}
.main_nav {
  flex: 1;
  justify-content: center;
  color: #ffffff;
  font-size: 20px;
  font-weight: bold;
  line-height: 56px;
  width: 160px;
  align-items: center;
}
.main_icon {
  width: 12px;
  height: 8px;
  margin-left: 14px;
}
.main_tit {
  position: relative;
}
.main_txt {
  position: absolute;
  width: 110px;
  text-align: center;
  line-height: 44px;
  font-size: 18px;
  background: #2a2a2a;
  top: 50%;
  margin-top: -26px;
  left: 50%;
  margin-left: -55px;
  color: #c4c4c4;
}
.main_line {
  width: 100%;
  height: 2px;
  background: #444444;
}
.main_items {
  flex-wrap: wrap;
  margin-top: 22px;
}
.main_item {
  background: #373737;
  margin-right: 14px;
  margin-bottom: 24px;
}
.main_item:nth-child(4n + 4) {
  margin-right: 0;
}

.main_src {
  width: 192px;
  height: 192px;
  background: #333333;
}
.main_info {
  padding: 10px 6px;
  box-sizing: border-box;
  width: 192px;
  color: #f8f8f8;
}
.main_name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 8px;
  font-size: 14px;
}
.main_ename {
  font-size: 12px;
}
.main_box {
  margin-top: 8px;
  justify-content: space-between;
}
.main_price {
  font-size: 16px;
  line-height: 38px;
}
.main_price text {
  font-size: 12px;
}
.main_add {
  width: 38px;
  height: 38px;
  background: #c8ad67;
  border-radius: 5px;
  color: #232323;
  font-size: 30px;
  text-align: center;
  font-weight: bold;
  line-height: 34px;
}

.main_right_cont {
  background: #232323;
  width: 332px;
  height: 100%;
}
.r_item {
  box-sizing: border-box;
  padding-left: 14px;
  color: #c7c7c7;
  line-height: 50px;
  font-size: 18px;
  border: solid 1px rgba(255, 255, 255, 0);
  border-left: rgba(255, 255, 255, 0) 5px solid;
}
.addStyle {
  border: solid 1px #444444;
  border-left: #f3ca7e 5px solid;
  box-shadow: 0 0 4px #f3ca7e;
}
</style>

<style>
/* .uni-input input {
  height: 40px !important;
} */
</style>
